export function clip(ctx: CanvasRenderingContext2D,clip: () => void, callback: (res: any) => void | Promise<void>) {
    ctx.save();
    ctx.beginPath();
    let res = clip();
    ctx.clip();
    let result = callback(res);
    if(result) {
        result.then(() => {
            ctx.restore();
        })
    } else {
        ctx.restore();
    }
}